package com.randy.riolis.kontrakan.adapter;

import java.util.List;

import com.randy.riolis.kontrakan.R;
import com.randy.riolis.kontrakan.entity.Kontrakan;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

/**
 * @author RANDY
 * 
 */
public class KontrakanAdapter extends BaseAdapter {

	private LayoutInflater inflater;
	private List<Kontrakan> kontrakan;

	static class ViewHolder {
		ImageView thumb;
		TextView alamat;
		TextView harga;
	}

	public KontrakanAdapter(Context context, List<Kontrakan> kontrakan) {
		// TODO Auto-generated constructor stub
		inflater = LayoutInflater.from(context);
		this.kontrakan = kontrakan;
	}

	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return kontrakan.size();
	}

	@Override
	public Object getItem(int arg0) {
		// TODO Auto-generated method stub
		return kontrakan.get(arg0);
	}

	@Override
	public long getItemId(int arg0) {
		// TODO Auto-generated method stub
		return 0;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		// TODO Auto-generated method stub
		ViewHolder holder;

		if (convertView == null) {
			convertView = inflater
					.inflate(R.layout.single_list_kontrakan, null);

			holder = new ViewHolder();

			holder.alamat = (TextView) convertView
					.findViewById(R.id.alamatKontrakan);
			holder.harga = (TextView) convertView
					.findViewById(R.id.hargaKontrakan);
			holder.thumb = (ImageView) convertView
					.findViewById(R.id.thumbKontrakan);

			convertView.setTag(holder);
		} else {
			holder = (ViewHolder) convertView.getTag();
		}
		holder.harga.setText(kontrakan.get(position).getHarga());
		holder.alamat.setText(kontrakan.get(position).getAlamat());
		holder.thumb.setBackgroundResource(kontrakan.get(position).getGambar());

		return convertView;
	}
}
